package com.site.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.site.dao.AdvertiseDao;
import com.site.dto.AdvertiseBizBean;
import com.site.model.AdvertiseInfo;
import com.site.util.StringUtils;
import com.site.util.base.dao.BaseDaoImpl;
import com.site.util.extremetable.QueryPage;

/**
 * 广告
 * @author lee
 * @date 2013年11月30日
 */
@Repository
public class AdvertiseDaoImpl extends BaseDaoImpl implements AdvertiseDao {

	@Override
	public List<AdvertiseInfo> getAdvertiseList(QueryPage queryPage,
			AdvertiseBizBean advertiseBizBean) {
		StringBuffer hql = new StringBuffer("from AdvertiseInfo where 1=1 ");
		Map<String, Object> values = new HashMap<String, Object>();
		if(null != advertiseBizBean){
			if(!StringUtils.isEmpty(advertiseBizBean.getTitle())){
				hql.append(" and title like :title ");
				values.put("title", "%"+advertiseBizBean.getTitle()+"%");
			}
			if(!StringUtils.isEmpty(advertiseBizBean.getContent())){
				hql.append(" and content like :content ");
				values.put("content", "%"+advertiseBizBean.getContent()+"%");
			}
			if(!StringUtils.isEmpty(advertiseBizBean.getType())){
				hql.append(" and type =:type ");
				values.put("type", advertiseBizBean.getType());
			}
		}
		if(queryPage == null){
			return super.findByHQL(hql.toString(), values);
		} else {
			return super.findByHQL(queryPage, hql.toString(), values, false);
		}
	}

}
